package com.aioething.iot.beans;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Setter
@Getter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Node {
    private String id;
    private String value;
    private String label;
    private String parentCode;
    private Boolean checked = Boolean.FALSE;
    private List<Node> children;

    public void add(Node node) {
        if (node == null) {
            return;
        }
        if (this.children == null) {
            this.children = new ArrayList<>();
        }
        this.children.add(node);
    }

    public Node() {}

    public Node(String value, String label, String parentCode) {
        this.value = value;
        this.label = label;
        this.parentCode = parentCode;
    }

    public Node(String id, String value, String label, String parentCode) {
        this.id = id;
        this.value = value;
        this.label = label;
        this.parentCode = parentCode;
    }

    public Node(String value, String label) {
        this.value = value;
        this.label = label;
    }

    @Override
    public boolean equals(Object o) {
        Node node = (Node) o;
        return this.value.equals(node.getValue());
    }

    @Override
    public int hashCode() {
        return Objects.hash(value, label, parentCode, children);
    }
}
